class BlackDeathMelee extends BlackDeathWeapon
        abstract;

var float weaponLength;
var Actor LastHitActor;//Stores last thing the sword hit.
var float MomentumScale;//Scalar for how much momentum to put onto an enemy when attacked.
var name TipSocket;//name of the socket to end our wepon trace at
var name BaseSocket;//name of the socket to begin our trace at

	simulated function Activate()
	{
		local vector Start, End;
		//weaponLength = VSize(End - Start);
		//`log("BDMelee activated!!!!! (I HAVE THE POWER!)"@weaponLength);
		super.Activate();
		SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(TipSocket, End);
		SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(BaseSocket, Start);
		//AttachWeaponTo(Instigator.Mesh);
		weaponLength = VSize(End - Start);
		//`log("Start, end"@Start@End);
	}
	
	function Tick( FLOAT DeltaSeconds )
	{
		local vector Start, End, HitLocation, HitNormal;
		local Actor HitActor;
		Super.Tick( DeltaSeconds );
		
		//`log("State"@GetStateName());
		if(IsFiring())
		{
			SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(TipSocket, End);
			SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(BaseSocket, Start);
			HitActor = Trace(HitLocation, HitNormal, end, start, true,,, TRACEFLAG_Bullet);//Trace(HitLocation, HitNormal, End, Start, true);
			if ((VSize(HitLocation - Start) < weaponLength)&&(BlackDeathPawn(HitActor) != None) )
			{
				if(HitActor != LastHitActor)//if we hit a pawn and its not one we already hit
				{
					`log("doing attack on"@HitActor);
					`log("Last hit"@LastHitActor);
					doAttack(Pawn(HitActor), HitLocation);
					LastHitActor = HitActor;
				}
			}
		}
	}
	
	simulated function doAttack(Pawn AttackedPawn, Vector HitLocation)//Do the actual hit to the thing
	{
		local vector X, Y, Z, Momentum;
		GetAxes(Instigator.rotation, X, Y, Z);
		Momentum = MomentumScale * X /*+ MomentumScale * Y + MomentumScale * Z*/;//Find the player's rotation in vector form and multiple it by the force of the attack
		if(currentfiremode == 0)
		{
			AttackedPawn.TakeDamage(WeaponDamage, Instigator.Controller, HitLocation, Momentum, class'DmgType_Crushed');
		}
		if(currentfiremode == 1)
		{
			AttackedPawn.TakeDamage(HeavyWeaponDamage, Instigator.Controller, HitLocation, Momentum, class'DmgType_Crushed');
		}
	}

	simulated function bool HasAnyAmmo()
	{
		return true;//Weapon always has ammo
	}

	function ConsumeAmmo( byte FireModeNum )
	{
		//Melee weapons do not consume ammo
	}
	
	function int AddAmmo(int Amount)
	{
		//Melee weapons cannot get ammo
	}
	
	simulated state WeaponFiring
	{
		simulated function RefireCheckTimer()
		{
			Super.RefireCheckTimer();
			LastHitActor = None;
		}
	}
	
	simulated function Projectile ProjectileFire()
	{
		local Projectile proj;
		proj=super.ProjectileFire();
		ItemRemovedFromInvManager();
		Destroy();
		return proj;
	}

	simulated function CustomFire()
	{
		local BlackDeathPawn BDP;
		BDP = BlackDeathPawn(Instigator);
		`log("custom fire called with firemode: "@currentfiremode);
		if(BDP != none)
		{
			if(currentFireMode == 0)
			{
				LightSwing();
			}
			if(currentfireMode == 1)
			{
				HeavySwing();
			}
		}
	}
	
	simulated function LightSwing()
	{
		if(BlackDeathPawn(instigator) != none)
			{
				BlackDeathPawn(instigator).LightSwing(/*We need to have a varible to record item classes*/);
			}
	}
	
	simulated function HeavySwing()
	{
		if(BlackDeathPawn(instigator) != none)
		{
			BlackDeathPawn(instigator).HeavySwing(/*We need to have a varible to record item classes*/);
		}
	}
	

DefaultProperties
{
	Begin Object Class=SkeletalMeshComponent Name=PickupMesh
		bOnlyOwnerSee=false
		CastShadow=false
		bForceDirectLightMap=true
		bCastDynamicShadow=false
		CollideActors=true
		BlockRigidBody=true
		MaxDrawDistance=6000
		bForceRefPose=1
		bUpdateSkelWhenNotRendered=false
		bIgnoreControllersWhenNotRendered=true
		bAcceptsStaticDecals=FALSE
		bAcceptsDynamicDecals=FALSE
		bAllowAmbientOcclusion=false
		MotionBlurScale=0.0
		SkeletalMesh=SkeletalMesh'BD_Weapon.Greatsword_Weapon'
	End Object
	DroppedPickupMesh=PickupMesh
	DroppedPickupClass=class'DroppedPickup'
	
	WeaponDamage = 10; //How much damage the wepon does
	HeavyWeaponDamage = 20;//How much damage the heavy fire mode does
	
	FiringStatesArray(0)=WeaponFiring
	FiringStatesArray(1)=WeaponFiring
	WeaponFireTypes(0)=EWFT_Custom
	WeaponFireTypes(1)=EWFT_Custom
	
	WeaponProjectiles(0)=none
	//WeaponProjectiles(1)=class'ThorwnMelee'
	
	EquipTime=+0.33
	PutDownTime=+0.33
	
	StaminaCost(0)=5
	StaminaCost(1)=10
	
	FireInterval(0)=1.0
	FireInterval(1)=1.0
	
	Spread(0)=0.0
	Spread(1)=0.0

	AIRating=1.0
	
	WeaponEquipAnim=WeaponEquip
	FireAnim = VM_Stab
	
	TipSocket = Tip_Socket
	BaseSocket = base_Socket
	
	
	Begin Object Class=SkeletalMeshComponent Name=WeaponMesh
		bOnlyOwnerSee=false
		CollideActors=false
		AlwaysLoadOnClient=true
		AlwaysLoadOnServer=true
		MaxDrawDistance=4000
		bForceRefPose=1
		bUpdateSkelWhenNotRendered=false
		bIgnoreControllersWhenNotRendered=true
		bOverrideAttachmentOwnerVisibility=true
		bAcceptsDynamicDecals=FALSE
		//Animations=MeshSequenceA
		CastShadow=true
		bCastDynamicShadow=true
		MotionBlurScale=0.0
		bAllowAmbientOcclusion=false
		//Translation=(Z=1)
		//Rotation=(Roll=-400)
		//Scale=0.9
	End Object
	Mesh=WeaponMesh
}